<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>民俗文化 - 印象滑州网</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        :root {
            --primaryBlue: #007BFF;
            --secondaryBlue: #0056b3;
            --lightBlue: #e7f5ff;
            --starBlue: #2A4359;
            --ink: #333333;
            --jade: #F7FBFE;
            --autumnBlue: #8AA2B5;
            --glazeBlue: #3A5F7D;
            --paleBlueGrey: #E1E8ED;
            --stoneGreen: #5C877B;
            --bambooGreen: #7A9D8F;
        }
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
            line-height: 1.6;
            color: var(--ink);
            background-color: var(--jade);
        }
        /* 头部导航栏样式 */
        .nav-container {
            background-color: rgba(247, 251, 254, 0.95);
            padding: 1.2rem 3rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            box-shadow: 0 2px 20px rgba(0,0,0,0.05);
            position: fixed;
            width: 100%;
            top: 0;
            z-index: 1000;
            transition: all 0.3s ease;
            backdrop-filter: blur(10px);
        }
        .logo { display: flex; align-items: center; gap: 1rem; }
        .logo-icon {
            width: 80px; height: 80px; background: transparent; border-radius: 50%;
            display: flex; align-items: center; justify-content: center; transition: all 0.3s ease;
        }
        .logo-icon img { width: 100%; height: 100%; object-fit: contain; }
        .logo h1 {
            color: var(--starBlue);
            font-size: 1.8rem;
            font-weight: 600;
            letter-spacing: 1px;
            background: linear-gradient(45deg, var(--primaryBlue), var(--glazeBlue));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        .nav-links {
            display: flex;
            list-style: none;
            gap: 2.5rem;
        }
        .nav-links a {
            color: var(--starBlue);
            text-decoration: none;
            font-size: 1.1rem;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            transition: all 0.3s ease;
            position: relative;
        }
        .nav-links a::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 0;
            height: 2px;
            background: linear-gradient(90deg, var(--primaryBlue), var(--bambooGreen));
            transition: all 0.3s ease;
            transform: translateX(-50%);
        }
        .nav-links a:hover::after,
        .nav-links a.active::after { width: 100%; }
        .nav-links a:hover,
        .nav-links a.active { color: var(--primaryBlue); }

        /* 顶部大图区域 */
        .food-hero {
            height: 60vh;
            background: linear-gradient(135deg, var(--starBlue), var(--glazeBlue));
            display: flex;
            align-items: center;
            justify-content: center;
            text-align: center;
            color: var(--jade);
            margin-top: 80px;
            position: relative;
            overflow: hidden;
        }
        .food-hero::before {
            content: '';
            position: absolute;
            top: 0; left: 0; right: 0; bottom: 0;
            background: url('https://imgoss.henandaily.cn/app/images/20240308/1e82c7b6153447029ecea56f829cf735.jpg') center/cover;
            opacity: 0.55;
        }
        .food-hero-content { position: relative; z-index: 1; }
        .food-hero h2 {
            font-size: 3.5rem;
            margin-bottom: 1rem;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }
        .food-hero p {
            font-size: 1.5rem;
            max-width: 800px;
            margin: 0 auto;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
        }

        /* 民俗文化卡片样式 */
        .culture-list { max-width: 1100px; margin: 0 auto; padding: 4rem 2rem; display: flex; flex-direction: column; gap: 4rem;}
        .culture-card {
            display: flex;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 8px 32px 0 rgba(58,139,253,0.10);
            overflow: hidden;
            border-left: 8px solid var(--primaryBlue);
            transition: box-shadow 0.22s, transform 0.22s;
            position: relative;
        }
        .culture-card:nth-child(even) { flex-direction: row-reverse; border-left: none; border-right: 8px solid var(--glazeBlue);}
        .culture-media-container {
            min-width: 260px;
            max-width: 320px;
            background: var(--lightBlue);
            padding: 1.5rem;
            position: relative;
        }
        .culture-card:nth-child(even) .culture-media-container { background: #e1f0ff; }
        .culture-media-wrapper {
            position: relative;
            width: 100%;
            height: 220px;
            overflow: hidden;
            border-radius: 12px;
            box-shadow: 0 4px 16px rgba(58,139,253,0.10);
        }
        .culture-video {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            z-index: 1;
        }
        .culture-image-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 2;
        }
        .culture-image {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }
        .mosaic-container {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 3;
            display: none;
        }
        .mosaic-tile {
            position: absolute;
            background-size: 800% 400%; /* 4x2 马赛克 */
            opacity: 0;
            transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        }
        .video-control {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 60px;
            height: 60px;
            background-color: rgba(0,0,0,0.6);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            opacity: 0;
            transition: opacity 0.3s;
            cursor: pointer;
            z-index: 5;
        }
        .culture-media-wrapper:hover .video-control {
            opacity: 1;
        }
        
        .culture-content {
            flex: 1;
            padding: 2.2rem 2rem 2.2rem 2rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }
        .culture-title {
            color: var(--primaryBlue);
            font-size: 1.5rem;
            font-weight: 700;
            margin-bottom: 0.7rem;
        }
        .culture-description {
            color: var(--autumnBlue);
            font-size: 1.08rem;
            line-height: 1.8;
            margin-bottom: 1.2rem;
        }
        .culture-tags {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        .culture-tag {
            background: var(--lightBlue);
            color: var(--primaryBlue);
            padding: 0.3rem 0.8rem;
            border-radius: 20px;
            font-size: 0.9rem;
        }
        
        /* 页脚样式 */
        footer { background: linear-gradient(135deg, var(--starBlue), var(--glazeBlue)); color: var(--jade); padding: 3rem 2rem; text-align: center;}
        .footer-content p { font-size: 1rem; opacity: 0.8; }

        @media (max-width: 900px) {
            .culture-card, .culture-card:nth-child(even) { flex-direction: column; border-left: 8px solid var(--primaryBlue); border-right: none;}
            .culture-media-container { min-width: 0; max-width: 100%; }
        }
        @media (max-width: 768px) {
            .nav-container { padding: 1rem; flex-direction: column; }
            .nav-links { margin-top: 1rem; flex-direction: column; align-items: center; gap: 1rem; }
            .food-hero h2 { font-size: 2.5rem; }
            .food-hero p { font-size: 1.2rem; }
            .culture-list { padding: 2rem 0.5rem; }
            .culture-content { padding: 1.2rem 1rem; }
        }
    </style>
</head>
<body>
    <header>
        <nav class="nav-container">
            <div class="logo">
                <div class="logo-icon">
                    <img src="hz.png" alt="滑州网logo">
                </div>
                <h1>印象滑州网</h1>
            </div>
            <ul class="nav-links">
                <li><a href="index.html">首页</a></li>
                <li><a href="food.html">美食介绍</a></li>
                <li><a href="scenery.html">景点介绍</a></li>
                <li><a href="culture.html" class="active">民俗文化</a></li>
                <li><a href="message.html">在线留言</a></li>
            </ul>
        </nav>
    </header>
    <main>
        <section class="food-hero">
            <div class="food-hero-content">
                <h2>民俗文化</h2>
                <p>感受滑州独特的民俗风情与文化底蕴</p>
            </div>
        </section>
        <section class="culture-list" id="cultureList">
            <!-- 民俗文化卡片将通过JavaScript动态加载 -->
        </section>
    </main>
    <footer>
        <div class="footer-content">
            <p>&copy; 2025 印象滑州网 版权所有</p>
        </div>
    </footer>
    <script>
        async function loadCultureData() {
            try {
                const response = await fetch('http://localhost:3000/cultures');
                const cultures = await response.json();
                const list = document.getElementById('cultureList');
                list.innerHTML = '';
                
                cultures.forEach(item => {
                    const card = `
                        <div class="culture-card">
                            <div class="culture-media-container" data-id="${item.id}">
                                <div class="culture-media-wrapper">
                                    <video class="culture-video" poster="${item.videoPoster || 'https://picsum.photos/800/450?random=' + item.id}" muted loop>
                                        <source src="${item.video}" type="video/mp4">
                                        您的浏览器不支持视频播放。
                                    </video>
                                    <div class="culture-image-container">
                                        <img src="${item.image}" alt="${item.title}" class="culture-image">
                                        <div class="mosaic-container"></div>
                                    </div>
                                    <div class="video-control">
                                        <i class="fa fa-play"></i>
                                    </div>
                                </div>
                            </div>
                            <div class="culture-content">
                                <div class="culture-title">${item.title}</div>
                                <div class="culture-description">${item.description}</div>
                                <div class="culture-tags">
                                    ${(item.tags || []).map(tag => `<span class="culture-tag">${tag}</span>`).join('')}
                                </div>
                            </div>
                        </div>
                    `;
                    list.innerHTML += card;
                });
                
                // 初始化图片交互
                initMediaInteractions();
            } catch (error) {
                console.error('加载民俗文化数据失败:', error);
            }
        }
        
        function initMediaInteractions() {
            const mediaWrappers = document.querySelectorAll('.culture-media-wrapper');
            
            mediaWrappers.forEach(wrapper => {
                const imageContainer = wrapper.querySelector('.culture-image-container');
                const image = wrapper.querySelector('.culture-image');
                const mosaicContainer = wrapper.querySelector('.mosaic-container');
                const video = wrapper.querySelector('.culture-video');
                const control = wrapper.querySelector('.video-control');
                
                let isPlaying = false;
                let isImageVisible = true;
                
                // 鼠标进入时显示马赛克动画
                wrapper.addEventListener('mouseenter', () => {
                    if (!isImageVisible || isPlaying) return;
                    
                    // 显示马赛克容器
                    mosaicContainer.style.display = 'block';
                    
                    // 创建马赛克方块
                    createMosaicTiles(image, mosaicContainer);
                    
                    // 设置延迟后隐藏图片并播放视频
                    setTimeout(() => {
                        hideImageAndPlayVideo(imageContainer, video, control);
                        isImageVisible = false;
                        isPlaying = true;
                    }, 1200); // 动画持续时间
                });
                
                // 鼠标离开时重置
                wrapper.addEventListener('mouseleave', () => {
                    if (isImageVisible) {
                        // 重置马赛克
                        mosaicContainer.style.display = 'none';
                        mosaicContainer.innerHTML = '';
                    }
                });
                
                // 视频控制点击事件
                control.addEventListener('click', () => {
                    if (video.paused) {
                        video.play();
                        control.innerHTML = '<i class="fa fa-pause"></i>';
                    } else {
                        video.pause();
                        control.innerHTML = '<i class="fa fa-play"></i>';
                    }
                });
                
                // 视频结束时重置
                video.addEventListener('ended', () => {
                    isPlaying = false;
                    control.innerHTML = '<i class="fa fa-play"></i>';
                });
            });
        }
        
        function createMosaicTiles(image, mosaicContainer) {
            // 清空容器
            mosaicContainer.innerHTML = '';
            
            // 获取图片尺寸
            const imgWidth = image.offsetWidth;
            const imgHeight = image.offsetHeight;
            
            // 设置背景图片
            mosaicContainer.style.backgroundImage = `url(${image.src})`;
            mosaicContainer.style.backgroundSize = 'cover';
            
            // 创建4x2的马赛克方块
            const rows = 2;
            const cols = 4;
            const tileWidth = imgWidth / cols;
            const tileHeight = imgHeight / rows;
            
            // 创建并定位每个方块（有序排列）
            for (let i = 0; i < rows; i++) {
                for (let j = 0; j < cols; j++) {
                    const tile = document.createElement('div');
                    tile.classList.add('mosaic-tile');
                    
                    // 设置方块大小和位置
                    tile.style.width = `${tileWidth}px`;
                    tile.style.height = `${tileHeight}px`;
                    tile.style.left = `${j * tileWidth}px`;
                    tile.style.top = `${i * tileHeight}px`;
                    
                    // 设置背景图片位置
                    tile.style.backgroundImage = `url(${image.src})`;
                    tile.style.backgroundSize = `${imgWidth * cols}px ${imgHeight * rows}px`;
                    tile.style.backgroundPosition = `-${j * imgWidth}px -${i * imgHeight}px`;
                    
                    // 设置初始位置（从边缘向中心移动）
                    const startX = j < cols/2 ? -tileWidth * (cols/2 - j) : tileWidth * (j - cols/2 + 1);
                    const startY = i < rows/2 ? -tileHeight * (rows/2 - i) : tileHeight * (i - rows/2 + 1);
                    
                    tile.style.transform = `translate(${startX}px, ${startY}px)`;
                    tile.style.opacity = '0.8';
                    
                    // 添加到容器
                    mosaicContainer.appendChild(tile);
                    
                    // 延迟应用动画（让方块按顺序出现）
                    setTimeout(() => {
                        tile.style.transform = 'translate(0, 0)';
                        tile.style.opacity = '1';
                    }, 100 * (i * cols + j));
                }
            }
        }
        
        function hideImageAndPlayVideo(imageContainer, video, control) {
            // 隐藏图片容器
            imageContainer.style.opacity = '0';
            imageContainer.style.transition = 'opacity 0.5s ease';
            
            // 确保视频已加载
            if (video.readyState >= 2) { // HAVE_CURRENT_DATA 或更高
                video.play().catch(error => {
                    console.error("视频播放失败:", error);
                });
                control.innerHTML = '<i class="fa fa-pause"></i>';
            } else {
                // 视频尚未加载，监听canplay事件
                video.addEventListener('canplay', function onCanPlay() {
                    video.removeEventListener('canplay', onCanPlay);
                    video.play().catch(error => {
                        console.error("视频播放失败:", error);
                    });
                    control.innerHTML = '<i class="fa fa-pause"></i>';
                });
                
                // 开始加载视频
                video.load();
            }
        }
        
        document.addEventListener('DOMContentLoaded', loadCultureData);
    </script>
</body>
</html>
